package com.imagination.applet.domain.aiimage.model;

import com.imagination.applet.domain.adapter.OSSConfiguration;
import com.imagination.applet.domain.common.entity.AbstractEntity;
import com.imagination.applet.domain.common.entity.ImageEntity;
import com.imagination.applet.domain.utils.OssUtil;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;


@SuperBuilder
@Entity
@Table(name = "t_ai_images")
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class AIImage  implements ImageEntity {
    public static final String PREFIX_PATH = "aiimages/";

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;

    @Column(name = "channel_type")
    private String channelType;

    @Column(name = "topic_type")
    private String topicType;

    @Column(name = "topic_id")
    private Long topicId;

    @Column(name = "image_path")
    private String imagePath;

    @Column(name = "prompt")
    private String prompt;

    @Column(name = "sort")
    private Integer sort;


    @Column(name = "model_name")
    private String modelName;

    @Column(name = "negative_prompt")
    private String negativePrompt;

    @Column(name = "sampler")
    private String sampler;

    @Column(name = "name")
    private String name;

    @Column(name = "del_flag")
    private String delFlag;

    @Column(name = "inference_steps")
    private Integer inferenceSteps;

    @Column(name = "cfg_scale")
    private Double cfgScale;

    @Column(name = "denoise")
    private Double denoise;

    @Column(name = "instant_weight")
    private Double instantWeight;

    @Column(name = "controlnet_weight")
    private Double controlnetWeight;

    @Override
    public String getPath() {
        return AIImage.PREFIX_PATH + imagePath;
    }

    @Override
    public String getLink() {
        String[] split = imagePath.split(",");
        for (int i = 0; i < split.length; i++) {
            split[i] = OssUtil.getTempUrl(split[i]);
        }
        return String.join(",",split);
    }

}
